package com.lutzyt.delivery.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;

/**
 * @author zyt
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

  private HttpSession httpSession;

  @Override
  public void insertFill(MetaObject metaObject) {
    String createName = "system";
    Object username = httpSession.getAttribute("username");
    if (username != null) {
      createName = username.toString();
    }
    this.strictInsertFill(metaObject, "creatorName", String.class, createName);
  }

  @Override
  public void updateFill(MetaObject metaObject) {

  }

  @Autowired
  public void setHttpSession(HttpSession httpSession) {
    this.httpSession = httpSession;
  }
}